package com.center.common.tool;

/**
 * @Auther: chenzheng
 * @date: $ $
 */
public class RandomUtil {

    private static char mapTable[] = {
            '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', '0', '1',
            '2', '3', '4', '5', '6', '7',
            '8', '9'};

    public static String randomString(int length) {
        return randomStringWithMap(length,mapTable);
    }

    public static String randomStringWithMap(int length,char[] chars) {
        //取随机产生的码
        String strEnsure = "";
        //4代表4位验证码,如果要生成更多位的认证码,则加大数值
        for (int i = 0; i < length; ++i) {
            strEnsure += chars[(int) (chars.length * Math.random())];
        }
        return strEnsure;
    }

}
